package java07;
import java.util.Scanner;
public class Main045{
	

private int balance;

synchronized void  deposit(int money){
	
	this.balance  = this.balance + money;
	if(this.balance > 0) notify();
}

synchronized void  withdraw(int money) {
	try{
		
	while(this.balance - money < 0){
		wait ();
	}
	this.balance  = this.balance - money;
	
	}catch(Exception e){
		
	}

	/*这里是deposit代码*/
	/*这里是withdraw代码的前半部分*/
	    if(balance<0) //这里是withdraw代码的后半部分。
	        throw new IllegalStateException(balance+"");				
	    }

	/*系统已有代码，无需关注*/

}
